﻿<views:HomeView
    xmlns:Controls="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
    x:Class="SpaceNeedle.x6473.WindowsPhone.Views.Home"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:views="clr-namespace:SpaceNeedle.x6473.WindowsPhone.Views"
    xmlns:controls="clr-namespace:SpaceNeedle.x6473.WindowsPhone.Controls"
    xmlns:viewmodels="clr-namespace:SpaceNeedle.x6473.WindowsPhone.ViewModels"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SpaceNeedle.x6473.WindowsPhone.Common"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:toolkitPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" shell:SystemTray.Opacity="0">

    <d:Page.DataContext>
        <viewmodels:HomeViewModelSampleData/>
    </d:Page.DataContext>
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="TicketsHeaderTemplate">
            <Grid>
                <ContentPresenter>
                    <TextBlock Text="{Binding}" Tap="OnTicketsHeader_Tap" />
                </ContentPresenter>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="AlertsHeaderTemplate">
            <Grid>
                <ContentPresenter>
                    <TextBlock Text="{Binding}" Tap="OnAlertsHeader_Tap" />
                </ContentPresenter>
            </Grid>
        </DataTemplate>
        
        <DataTemplate x:Key="CallsHeaderTemplate">
            <Grid>
                <ContentPresenter>
                    <TextBlock Text="{Binding}" Tap="OnCallsHeader_Tap" />
                </ContentPresenter>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="CityDetailsHeaderTemplate">
            <Grid>
                <ContentPresenter>
                    <TextBlock Text="{Binding}" Tap="OnCityDetailsHeader_Tap" />
                </ContentPresenter>
            </Grid>
        </DataTemplate>

        <shell:ApplicationBar x:Name="appbarFull" IsVisible="True" IsMenuEnabled="True" Mode="Default" Opacity="1.0" >
            <shell:ApplicationBarIconButton x:Name="callAppBarButton" IconUri="/Assets/AppBar/feature.phone.png" Text="ligar central" Click="OnCallAppBarButton_Click"/>
            <shell:ApplicationBarIconButton x:Name="clearAlertsAppBarButton" IconUri="/Assets/AppBar/cancel.png" Text="limpar" Click="OnClearAlertsAppBarButton_Click"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="uploadsMenuItem" Text="uploads" Click="OnUploadsMenuItem_Click"/>
                <!--<shell:ApplicationBarMenuItem x:Name="settingsMenuItem" Text="configurações" Click="OnSettingsMenuItem_Click"/>-->
                <shell:ApplicationBarMenuItem x:Name="aboutMenuItem" Text="sobre" Click="OnAboutMenuItem_Click"/>
                <shell:ApplicationBarMenuItem x:Name="signoutMenuItem" Text="sair" Click="OnSignOutMenuItem_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
        <shell:ApplicationBar x:Name="appbarHalf" IsVisible="True" IsMenuEnabled="True" Mode="Default" Opacity="1.0" >
            <shell:ApplicationBarIconButton x:Name="callAppBarButton2" IconUri="/Assets/AppBar/feature.phone.png" Text="ligar central" Click="OnCallAppBarButton_Click"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="uploadsMenuItem2" Text="uploads" Click="OnUploadsMenuItem_Click"/>
                <!--<shell:ApplicationBarMenuItem x:Name="settingsMenuItem2" Text="configurações" Click="OnSettingsMenuItem_Click"/>-->
                <shell:ApplicationBarMenuItem x:Name="aboutMenuItem2" Text="sobre" Click="OnAboutMenuItem_Click"/>
                <shell:ApplicationBarMenuItem x:Name="signoutMenuItem2" Text="sair" Click="OnSignOutMenuItem_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
        <shell:ApplicationBar x:Name="appbarMap" IsVisible="True" IsMenuEnabled="True" Mode="Default" Opacity="1.0" >
            <shell:ApplicationBarIconButton x:Name="callAppBarButton3" IconUri="/Assets/AppBar/feature.phone.png" Text="ligar central" Click="OnCallAppBarButton_Click"/>
            <shell:ApplicationBarIconButton x:Name="requestsAppBarButton" IconUri="/Assets/AppBar/manage.png" Text="lista" Click="OnRequestsAppBarButton_Click"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="uploadsMenuItem3" Text="uploads" Click="OnUploadsMenuItem_Click"/>
                <!--<shell:ApplicationBarMenuItem x:Name="settingsMenuItem2" Text="configurações" Click="OnSettingsMenuItem_Click"/>-->
                <shell:ApplicationBarMenuItem x:Name="aboutMenuItem3" Text="sobre" Click="OnAboutMenuItem_Click"/>
                <shell:ApplicationBarMenuItem x:Name="signoutMenuItem3" Text="sair" Click="OnSignOutMenuItem_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot">
        <phone:Panorama x:Name="homePanorama" Title="{Binding AppContent.Name}" SelectionChanged="OnHomePanorama_SelectionChanged">
            <phone:Panorama.Background>
                <ImageBrush ImageSource="{Binding CurrentTimeImage, Source={StaticResource TimeOfTheDayImageChooser}}" Stretch="UniformToFill" Opacity="0.5"/>
            </phone:Panorama.Background>

            <!--Panorama item one-->
            <phone:PanoramaItem x:Name="Requests" Header="{Binding StaticContent.NewRequestSectionTitle}">
                <Grid>

                    <Border  Margin="24,0,0,0" Width="120" Height="120" HorizontalAlignment="Left" VerticalAlignment="Top" Background="{StaticResource PhoneAccentBrush}" Tap="OnNewRequest_Tap">
                        <TextBlock Text="+" Margin="0,-25,0,0" Foreground="White" FontSize="110" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Border>
                    <TextBlock Text="{Binding StaticContent.NewRequestSectionText}" FontSize="36" TextWrapping="Wrap" VerticalAlignment="Top" Margin="70,170,0,0" HorizontalAlignment="Left">
                    </TextBlock>
                </Grid>
            </phone:PanoramaItem>

            <!--Panorama item two-->
            <phone:PanoramaItem x:Name="Calls" Header="{Binding StaticContent.CallsSectionTitle}" HeaderTemplate="{StaticResource CallsHeaderTemplate}">
                <Grid>
                    <Border Background="Transparent" Tap="OnMap_Tap">
                        <Controls:Map Name="map" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="15,0,0,20" IsHitTestVisible="False" />
                    </Border>
                </Grid>
            </phone:PanoramaItem>
            
            <!--Panorama item three-->
            <phone:PanoramaItem x:Name="Tickets" Header="{Binding StaticContent.ProtocolsSectionTitle}" HeaderTemplate="{StaticResource TicketsHeaderTemplate}">
                <Grid>
                    <ListBox x:Name="userTicketsListBox" Grid.Row="1" Margin="15,0,0,0" ItemsSource="{Binding UserTickets}" SelectionChanged="OnUserTicketsListBox_SelectionChanged" Visibility="{Binding UserTickets, Converter={StaticResource InverseIEnumerableCountToVisibilityConverter}}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,20">
                                    <StackPanel Orientation="Vertical" Background="{StaticResource PhoneAccentBrush}" >
                                        <Border Width="96" Height="76" VerticalAlignment="Top">
                                            <Image Source="{Binding RequestIcon}" Width="64" Height="64" Stretch="UniformToFill" VerticalAlignment="Center"/>
                                        </Border>
                                        <Border Background="#30000000" Height="30">
                                            <TextBlock FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" Foreground="White" Text="{Binding Status, Converter={StaticResource RequestItemStatusToStringConverter},ConverterParameter=true}" />
                                        </Border>
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical" Margin="10,0,0,0">
                                        <TextBlock FontSize="30" Text="{Binding RequestTitle}" TextWrapping="NoWrap" TextTrimming="WordEllipsis" HorizontalAlignment="Left" Width="300" />
                                        <TextBlock FontSize="22" Text="{Binding Address}" FontWeight="Bold" TextWrapping="NoWrap" TextTrimming="WordEllipsis" HorizontalAlignment="Left" Width="300"/>
                                        <TextBlock FontSize="22" Margin="0,0,0,0" Text="{Binding Description}" TextWrapping="NoWrap" TextTrimming="WordEllipsis" HorizontalAlignment="Left" Width="300"/>
                                        <toolkit:ContextMenuService.ContextMenu>
                                            <toolkit:ContextMenu IsZoomEnabled="false">
                                                <toolkit:MenuItem Header="Compartilhar" Foreground="Black" Tag="{Binding}" 
                                                  Click="OnShareTicket_Click" />
                                            </toolkit:ContextMenu>
                                        </toolkit:ContextMenuService.ContextMenu>
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <TextBlock Text="Não existem Protocolos disponíveis" Visibility="{Binding UserTickets, Converter={StaticResource IEnumerableCountToVisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

                </Grid>
            </phone:PanoramaItem>

            <!--Panorama item four-->
            <phone:PanoramaItem x:Name="Alerts" Header="{Binding StaticContent.AlertsSectionTitle}" HeaderTemplate="{StaticResource AlertsHeaderTemplate}">
                <Grid>
                    <ListBox Grid.Row="1" Margin="15,0,0,0" ItemsSource="{Binding Alerts}" Visibility="{Binding Alerts, Converter={StaticResource InverseIEnumerableCountToVisibilityConverter}}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <Border Background="{StaticResource PhoneAccentBrush}" HorizontalAlignment="Left">
                                        <TextBlock FontSize="30" Foreground="#FFFFFFFF" Text="{Binding Title}" TextTrimming="WordEllipsis" MaxWidth="400" Margin="5"/>
                                    </Border>
                                    <TextBlock Text="{Binding CreationDate, StringFormat='dd/MM HH:mm'}" FontWeight="Bold" />
                                    <TextBlock FontSize="22" Margin="0,0,0,20" Text="{Binding Description}" TextTrimming="WordEllipsis" MaxWidth="400"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <TextBlock Text="Não existem Alertas disponíveis" Visibility="{Binding Alerts, Converter={StaticResource IEnumerableCountToVisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Grid>
            </phone:PanoramaItem>

            <!--Panorama item five-->
            <phone:PanoramaItem x:Name="usefulNumbers" Header="{Binding StaticContent.PhonesSectionTitle}">
                <Grid>
                    <ListBox x:Name="usefulNumbersListBox" Grid.Row="1" Margin="15,0,25,0" ItemsSource="{Binding Phones}" SelectionChanged="OnUsefulNumbersListBox_SelectionChanged">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                            <StackPanel Margin="0,20,0,0" Orientation="Horizontal">
                                    <Image Source="{Binding CurrentThemeImage, Source={StaticResource PhoneImageChooser}}" Stretch="None" />
                                <TextBlock FontSize="30" Margin="10,0,0,0" VerticalAlignment="Center" Text="{Binding Title}" />
                            </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </phone:PanoramaItem>

            <!--Panorama item six-->
            <phone:PanoramaItem x:Name="Social" Header="{Binding StaticContent.SocialSectionTitle}">
                <Grid>
                    <StackPanel Margin="15,0,0,0">
                        <StackPanel Orientation="Horizontal">
                            <Image x:Name="facebookImage" Source="/Assets/Social/facebook-150.png" Stretch="UniformToFill" Width="150" Tap="OnFacebookImage_Tap" />
                            <Image x:Name="twitterImage" Source="/Assets/Social/twitter-150.png" Stretch="UniformToFill" Margin="20,0,0,0" Width="150" Height="150" Tap="OnTwitterImage_Tap"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </phone:PanoramaItem>

            <!--Panorama item seven-->
            <phone:PanoramaItem x:Name="CityDetails" Header="cidade" HeaderTemplate="{StaticResource CityDetailsHeaderTemplate}">
                <Grid>
                    <StackPanel Margin="15,0,0,0">
                        <StackPanel Orientation="Horizontal">
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </phone:PanoramaItem>
        </phone:Panorama>
        <ProgressBar Visibility="{Binding IsInProgress, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource ProgressStyle}" />
        <controls:NewtworkStatusControl/>
    </Grid>

</views:HomeView>